import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Stack;

import javax.swing.JOptionPane;

public class StivaDoctor { 

	private JOptionPane err_mesaj;
	//doctori

		public Stack<String> id_doctor(Connection con) {
			Stack<String> id_doctor = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					id_doctor.add(rs.getString("id_doctor"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return id_doctor;
		}

		public Stack<String> nume_doctor(Connection con) {
			Stack<String> nume_doctor = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					nume_doctor.add(rs.getString("nume_doctor"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return nume_doctor;
		}
		
		public Stack<String> specializare(Connection con) {
			Stack<String> specializare = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					specializare.add(rs.getString("specializare"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return specializare;
		}

		public Stack<String> varsta(Connection con) {
			Stack<String> varsta = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					varsta.add(rs.getString("varsta"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return varsta;
		}
		
		public Stack<String> nume_spital(Connection con) {
			Stack<String> nume_spital = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					nume_spital.add(rs.getString("nume_spital"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return nume_spital;
		}
		
		public Stack<String> reclamatii(Connection con) {
			Stack<String> reclamatii = new Stack<String>();
			try {
				PreparedStatement ps = con
						.prepareStatement("Select * from doctori");
				ResultSet rs = ps.executeQuery();
				while (rs.next()) {
					reclamatii.add(rs.getString("reclamatii"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return reclamatii;
		}
	
		public void stergedoctor(Connection con, String CUI) 
		{
			String sql = "DELETE FROM doctori WHERE id_doctor='" + CUI + "'";
			try {
				PreparedStatement ps = con.prepareStatement(sql);
				ps.executeUpdate();
				err_mesaj = new JOptionPane();
				err_mesaj.showMessageDialog(null,
						"Doctor sters cu success !", sql, err_mesaj.INFORMATION_MESSAGE);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		public void modificacolCF(Connection con,
				String id_doctor, 
				String nume_doctor,
				String specializare, 
				String varsta, 
				String nume_spital, 
				String reclamatii
				) {
			String sql = "UPDATE doctori SET id_doctor='" + id_doctor
					+ "' , nume_doctor='" + nume_doctor
					+ "' , specializare='" + specializare
					+ "' , varsta='" + varsta
					+ "' , nume_spital='" + nume_spital
					+ "' , reclamatii='" + reclamatii
					+"'";
			try {
				PreparedStatement ps = con.prepareStatement(sql);
				ps.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		public void adaugadoctor(Connection con,
				String id_doctor, 
				String nume_doctor, 
				String specializare, 
				String varsta, 
				String nume_spital, 
				String reclamatii
				) {
			if ((id_doctor(con).contains(id_doctor))) {
				err_mesaj = new JOptionPane();
				err_mesaj.showMessageDialog(null,
						"Acest doctor deja exista in baza de date !", id_doctor, err_mesaj.ERROR_MESSAGE);

			} else {
				try {
					PreparedStatement ps = con
							.prepareStatement("INSERT INTO doctori (id_doctor, nume_doctor,specializare, varsta, nume_spital, reclamatii) VALUES('"
									+ id_doctor
									+ "','"
									+ nume_doctor
									+ "','"
									+ specializare
									+ "','"
									+ varsta
									+ "','"
									+ reclamatii
									+ "')");
					ps.executeUpdate();
					err_mesaj = new JOptionPane();
					err_mesaj.showMessageDialog(null,
							"Doctor adaugat cu succes !",id_doctor, err_mesaj.INFORMATION_MESSAGE);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
}
